package com.ascentive.finallyfast;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class Splash extends Activity {
	
	SharedPreferences settings = null;
	// PreferenceManager mPrefs = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
        /** set time to splash out */
        final int welcomeScreenDisplay = 2000;
        /** create a thread to show splash up to splash time */
        Thread welcomeThread = new Thread() {

        int wait = 0;

        @Override
        public void run() 
        {
        	try {
        		super.run();
        		/**
        		 * use while to get the splash time. Use sleep() to increase
        		 * the wait variable for every 100L.
        		 */
        		while (wait < welcomeScreenDisplay) {
        			sleep(100);
        			wait += 100;
        		}
        	} catch (Exception e) {
        		System.out.println("EXc=" + e);
        	} finally {
        		/**
        		 * Called after splash times up. Do some action after splash
        		 * times up. Here we moved to another main activity class
        		 */
//        		if (readPrefs() == true)
//        			startActivity(new Intent(Splash.this, MainScreenActivity.class));
//        		else
//        			startActivity(new Intent(Splash.this, WelcomePage.class));
        		
        		startActivity(new Intent(Splash.this, WelcomePage.class));
        		finish();
        	}
        }
        };
        welcomeThread.start();

    }

	public boolean readPrefs() {
		// SharedPreferences prefs =
		// PreferenceManager.getDefaultSharedPreferences(this);
		// mPrefs = (PreferenceManager)
		// PreferenceManager.getDefaultSharedPreferences(this);

		// second argument is the default to use if the preference can't be
		// found
		// Boolean welcomeScreenShown = ((SharedPreferences)
		// mPrefs).getBoolean("welcomeScreenShownPref", false);
		// return welcomeScreenShown;
		boolean ret = false;
		settings = getSharedPreferences("my_prefs_file", MODE_PRIVATE);
		ret = settings.getBoolean("welcome", false);
		return ret;
    }
}